<?php
class MHandleRecord extends MY_Model {

	protected $table = 'handle_record';
	
	public function getList($limit, $sort=false){
	    $this->db->select($this->table.'.*,user.account');
	    $this->db->distinct();
	    $this->db->from($this->table);
	    $this->db->join('user', $this->table.'.user_id=user.id','LEFT');
	    if($limit){
	        $this->db->limit($limit['limit'],$limit['offset']);
	    }
	    $this->formfilter->doFilter();
	    if($sort){
	        $this->db->order_by($this->table.'.id', 'asc');
	    }else{
	        $this->db->order_by($this->table.'.id', 'desc');
	    }
	    $query = $this->db->get();
	    return $query->result();
	}
	
	public function getCount(){
	    $this->db->select('count(distinct '.$this->db->dbprefix($this->table).'.id) as num');
	    $this->db->from($this->table);
	    $this->db->join('user', $this->table.'.user_id=user.id','LEFT');
	    $this->formfilter->doFilter();
	    $tmp = $this->db->get()->result();
	    return (int)$tmp[0]->num;
	}
	
	public function getById($id){
		$query = $this->db->where('id',$id)->get($this->table);
		return $query->row();
	}
	
}
